#ifndef __I2C_BSP_H__
#define __I2C_BSP_H__

#include "i2c.h"
#include "gpio_bsp.h"
#include "cmsis_os.h"

#define I2C1_OBJ_EN
#define I2C2_OBJ_EN
#define I2C3_OBJ_EN

typedef enum
{
#ifdef I2C1_OBJ_EN
  I2C1_OBJ,
#endif
#ifdef I2C2_OBJ_EN
  I2C2_OBJ,
#endif
#ifdef I2C3_OBJ_EN
  I2C3_OBJ,
#endif
  I2C_OBJ_NUM_MAX
}i2c_obj_id_t;

typedef struct
{
  I2C_HandleTypeDef *hi2c;
  SemaphoreHandle_t mutex;
  uint32_t clk_speed;
  gpio_obj_t clk_pin;
  gpio_obj_t sda_pin;
}i2c_obj_t;

typedef enum
{
  reg_8bits=1,
  reg_16bits,
}reg_bits_t;

void i2c_obj_close (i2c_obj_id_t obj_id);
int i2c_obj_open(i2c_obj_id_t obj_id, uint32_t clk_speed);
int i2c_obj_read (i2c_obj_id_t obj_id, uint8_t chip_addr, uint16_t reg, reg_bits_t reg_bits, uint8_t* dbuf, uint8_t dsize);
int i2c_obj_write(i2c_obj_id_t obj_id, uint8_t chip_addr, uint16_t reg, reg_bits_t reg_bits, uint8_t* dbuf, uint8_t dsize);

#endif
